#!/usr/bin/env python
# -*- coding: utf-8 -*-
from flask import Flask
from flask_cors import CORS
from .config import get_config

def create_app():
    """
    创建flask app
    :return:
    """
    app = Flask(__name__)

    # 加载配置
    config_class = get_config()
    app.config.from_object(config_class)

    # 跨域
    CORS(app)

    # 初始化插件
    from applications.extensions import init_plugs
    init_plugs(app)

    # 注册蓝图
    from applications.views import init_register_views
    init_register_views(app)

    app.logger.info(f"当前环境: {app.config['FLASK_ENV']} / DEBUG={app.config['DEBUG']} / LOG_LEVEL={app.config['LOG_LEVEL']}")

    return app
